package com.abc.robot01.activity.compose

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Bookmarks
import androidx.compose.material.icons.filled.CalendarMonth
import androidx.compose.material.icons.filled.Dashboard
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Group
import androidx.compose.material.icons.filled.Headphones
import androidx.compose.material.icons.filled.Image
import androidx.compose.material.icons.filled.JoinFull
import androidx.compose.material.icons.filled.Keyboard
import androidx.compose.material.icons.filled.Laptop
import androidx.compose.material.icons.filled.Map
import androidx.compose.material.icons.filled.Navigation
import androidx.compose.material.icons.filled.Outbox
import androidx.compose.material.icons.filled.PushPin
import androidx.compose.material.icons.filled.QrCode
import androidx.compose.material.icons.filled.Radio
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.DismissibleDrawerSheet
import androidx.compose.material3.DismissibleNavigationDrawer
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.PermanentDrawerSheet
import androidx.compose.material3.PermanentNavigationDrawer
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.abc.robot01.R
import com.abc.robot01.activity.MYBLACK
import com.abc.robot01.activity.MYBLUE
import com.abc.robot01.activity.MyFont_Size
import com.abc.robot01.activity.mysp
import com.abc.robot01.activity.px
import kotlinx.coroutines.launch

//https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/PullToRefreshSamples.kt

class DialogSamples : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e("FirstFragment", "MainActivity  onCreate");
        setContent {
            MaterialTheme {
                Surface {
                    Column(
                        modifier = Modifier
                            .fillMaxSize()
                            .verticalScroll(rememberScrollState())
                            .padding(8.dp),
                        verticalArrangement = Arrangement.spacedBy(8.dp)
                    ) {
                        Spacer(modifier = Modifier.height(2.dp))
                        MinimalDialog {}
//                        AlertDialogExample({},{},"111","123",Icons.Default.Favorite)
                        Spacer(modifier = Modifier.height(2.dp))
//                        MyDialog({}){a,b,c->}
                        Spacer(modifier = Modifier.height(2.dp))


//                        DismissibleNavigationDrawerSample()
//                        ModalNavigationDrawerSample()
//                        PermanentNavigationDrawerSample()
                    }
                }
            }
        }
    }

    companion object {
    }
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AlertDialogExample(
    onDismissRequest: () -> Unit,
    onConfirmation: () -> Unit,
    dialogTitle: String,
    dialogText: String,
    icon: ImageVector,
) {
    AlertDialog(
        icon = {
            Icon(icon, contentDescription = "Example Icon")
        },
        title = {
            Text(text = dialogTitle)
        },
        text = {
            Text(text = dialogText)
        },
        onDismissRequest = {
            onDismissRequest()
        },
        confirmButton = {
            TextButton(
                onClick = {
                    onConfirmation()
                }
            ) {
                Text("Confirm")
            }
        },
        dismissButton = {
            TextButton(
                onClick = {
                    onDismissRequest()
                }
            ) {
                Text("Dismiss")
            }
        }
    )
}

@Composable
fun Left() {
    Column(modifier = Modifier.padding(top = 30.px)) {
        BasicText(
            modifier = Modifier.offset(x = 28.px),
            text = "20241125122545",
            style = TextStyle(
                fontWeight = FontWeight.Normal,
                fontSize = 26.mysp,
                color = MYBLACK,
            ),
        )
        Spacer(modifier = Modifier.height(36.px))
        Column(modifier = Modifier.padding(start = 46.px)) {
            BasicText(
                text = "数据类型: 原始结构",
                style = TextStyle(
                    fontWeight = FontWeight.Normal,
                    fontSize = 24.mysp,
                    color = Color.Black.copy(alpha = 0.6f),
                ),
            )

            Spacer(modifier = Modifier.height(30.px))
            BasicText(
                text = "生成时间：2024-11-25 11:55:45",
                style = TextStyle(
                    fontWeight = FontWeight.Normal,
                    fontSize = 24.mysp,
                    color = Color.Black.copy(alpha = 0.6f),
                ),
            )
            Spacer(modifier = Modifier.height(30.px))
            BasicText(
                text = "备注：备注",
                style = TextStyle(
                    fontWeight = FontWeight.Normal,
                    fontSize = 24.mysp,
                    color = Color.Black.copy(alpha = 0.6f),
                ),
            )
            Spacer(modifier = Modifier.height(30.px))
            Spacer(
                modifier = Modifier
                    .height(4.px)
                    .width(380.px)
                    .background(Color.Black.copy(alpha = 0.80f))
            )
            Spacer(modifier = Modifier.height(30.px))
            BasicText(
                text = "客户名称：王小二",
                style = TextStyle(
                    fontWeight = FontWeight.Normal,
                    fontSize = 24.mysp,
                    color = Color.Black.copy(alpha = 0.6f),
                ),
            )
            Spacer(modifier = Modifier.height(30.px))
            BasicText(
                text = "客户手机：13298545122",
                style = TextStyle(
                    fontWeight = FontWeight.Normal,
                    fontSize = 24.mysp,
                    color = Color.Black.copy(alpha = 0.6f),
                ),
            )
        }
    }
}


@Composable
fun MinimalDialog(onDismissRequest: () -> Unit) {
    Dialog(
        properties = DialogProperties(
            usePlatformDefaultWidth = false,
            dismissOnBackPress = false, // 禁用返回按钮
            dismissOnClickOutside = false // 禁用点击外部关闭对话框
        ),
        onDismissRequest = { onDismissRequest() }) {
        Box(
            modifier = Modifier
                .background(color = Color.White, shape = RoundedCornerShape(40.px))
                .size(1364.px, 860.px)
                .padding(30.px),
        ) {

            Row {
                Box(
                    modifier = Modifier
                        .size(800.px, 800.px)
                        .background(
                            color = Color.Red,
                            shape = RoundedCornerShape(30.px)
                        ),
                ) {


                }
                Left()
            }

            com.abc.robot01.activity.MyButton01(
                modifier = Modifier.align(Alignment.BottomEnd),
                text = "应用", size = DpSize(144.px, 34.px), textColor = Color.White,
                containerColor = MYBLUE, shape = RoundedCornerShape(6.px)
            ) {
            }

            Image(
                modifier = Modifier.align(Alignment.TopEnd).clickable {



                },
                painter = painterResource(R.drawable.close2),
                contentDescription = "")


        }
    }
}